<%@ page contentType="text/html;charset=UTF-8" language="java"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="common/global.jsp"%>
<%@ include file="common/meta.jsp"%>
<%@ include file="common/include-base-styles.jsp"%>
<link rel="stylesheet" href="${ctx}/assets/css/bootstrap-editable.css">
</head>

<body>
	<%@ include file="common/head.jsp"%>

	<div class="main-container" id="main-container">
		<script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>

		<div class="main-container-inner">
			<%@ include file="common/sidebar.jsp"%>
			<div class="main-content">
				<%@ include file="common/bread.jsp"%>
				<div class="page-content">
					<!-- PAGE CONTENT START -->


					<div class="row">
						<div class="col-xs-12">
							<div class="widget-box">
								<div class="widget-header">
									<h4>公文意见</h4>
								</div>
								<div class="widget-body">
									<div class="widget-main">
										<table id="filepage">

										</table>
									</div>
								</div>


							</div>
						</div>

					</div>

					<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
						aria-labelledby="myModalLabel">
						<div class="modal-dialog" role="document">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal"
										aria-label="Close">
										<span aria-hidden="true">×</span>
									</button>
									<h4 class="modal-title" id="myModalLabel">意见修改</h4>
								</div>
								<div class="modal-body">

									<div class="form-group">
										<label for="txt_departmentname">意见</label>
										<textarea name="txt_content" class="form-control"
											id="txt_content" placeholder="意见"></textarea>
										<input type="hidden" name="content_id" id="content_id" />
									</div>

								</div>
								<div class="modal-footer">
									<button type="button" class="btn btn-default"
										data-dismiss="modal">
										<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭
									</button>
									<button type="button" id="btn_submit" class="btn btn-primary"
										data-dismiss="modal">
										<span class="glyphicon glyphicon-floppy-disk"
											aria-hidden="true"></span>保存
									</button>
								</div>
							</div>
						</div>
					</div>
					<!-- PAGE CONTENT ENDS -->
				</div>
				<!-- /.page-content -->

				<!-- /.page-content -->
			</div>
			<!-- /.main-content -->
		</div>
		<!-- /.main-container-inner -->

		<a href="#" id="btn-scroll-up"
			class="btn-scroll-up btn btn-sm btn-inverse"> <i
			class="icon-double-angle-up icon-only bigger-110"></i>
		</a>
	</div>
	<!-- /.main-container -->
	<input type="hidden" id="summaryId" value="${id}">

	<!-- basic scripts -->
	<%@ include file="common/basicScripts.jsp"%>
	<script src="${ctx}/assets/js/bootbox.min.js"></script>


	<script type="text/javascript">
$(function () {
	
	
    //1.初始化Table
    var oTable = new TableInit();
    oTable.Init();
    
  	//当点击查询按钮的时候执行  
    $("#button").bind("click", function(){
    	  $('#filepage').bootstrapTable('refresh');
    });
  	
  	$("#btn_submit").bind("click",function(){
  		$.post(ctx + '/backworkflow/updateopinion',{
  			'content' : $("#txt_content").val(),
  			'contentId' : $("#content_id").val()
  		},function(data){
  			if(data.state){
  				bootbox.alert("修改成功");  				
  	    	  	$('#filepage').bootstrapTable('refresh');
  			}else{
  				bootbox.alert("修改失败");
	  	    	$('#filepage').bootstrapTable('refresh');
  			}
  			
  		});
  	});
	
});

var editWin = function(id){
	$.post(ctx + '/backworkflow/selectOneOpinion',{
			'id' : id
		},function(data){
			$('#content_id').val(id);
			console.log(data.content);
			$('#txt_content').val(data.content);
			$('#myModal').modal();
			
	});
	
}

var deleteWin = function(id){
	bootbox.confirm("是否删除?", function(result) {
		if(result) {
			if(result){
				$.post(ctx + '/backworkflow/deleteopinion',{
		  			'contentId' : id
		  		},function(data){
		  			if(data.state){
		  				bootbox.alert("删除成功");
		  	    	  	$('#filepage').bootstrapTable('refresh');
		  			}else{
		  				bootbox.alert("删除失败");
			  	    	$('#filepage').bootstrapTable('refresh');
		  			}
		  			
		  		});
			}
			
		}
	});
}

var TableInit = function () {
    var oTableInit = new Object();
    //初始化Table
    oTableInit.Init = function () {
        $('#filepage').bootstrapTable({
            url: ctx+'/backworkflow/selectopinion',         //请求后台的URL（*）        
            method: 'get',                      //请求方式（*）
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            queryParams: oTableInit.queryParams,//传递参数（*）
            pagination: false,  //开启分页  
            height:300,        
            columns: [{
                field: 'orgMember.name',
                title: '用户名'
            }, {
                field: 'content',
                title: '意见',
                editable: {
                    type: 'text',
                    title: '意见',
                    validate: function (v) {
                        if (!v) return '意见不能为空';

                    }
                }
            }, {
                field: 'createTime',
                title: '意见时间'
            }, {
                field: 'operation',
                title: '操作',
                formatter:function(value,row,index){
                	return "<a href=javascript:editWin(\""+row.id+"\")>编辑</a>&nbsp;&nbsp;<a href=javascript:deleteWin(\""+row.id+"\")>删除</a>"
                }
            } ]
        });
    };

    //得到查询的参数
    oTableInit.queryParams = function (params) {
        var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
        		id: $("#summaryId").val()
        };
        return temp;
    };
    
    
    return oTableInit;
};


</script>
</body>
</html>

